﻿using CQRSFramework.Commands;
using CQRSFramework.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace CQRSFramework.Infrustructures.Impl
{
    public class RoutingKeyProvider<T> : IRoutingKeyProvider<T>
    {
        private readonly IDictionary<Type, string> _dictionary = new Dictionary<Type, string>();
        public IEnumerable<string> GetAllRoutingKeys()
        {
            return _dictionary.Values.Distinct();
        }
        public string GetRoutingKey(T type)
        {
            if (typeof(ICommand).IsAssignableFrom(type.GetType()))
            {
                return "CommandTopic";
            }
            if (typeof(IDomainEvent).IsAssignableFrom(type.GetType()))
            {
                return "EventTopic";
            }
            return null;
        }
        //public string GetRoutingKey(Type type)
        //{
        //    string routingKey;
        //    if (!_dictionary.TryGetValue(type, out routingKey))
        //    {
        //        return null;
        //    }
        //    return routingKey;
        //}
    }
}
